copy = []
""" without using 'with'
### print(locals()) 
try:
	data = open("ata.txt")

	for each_line in data:
###		print(each_line, end='') ###
		if each_line != "":
			copy.append(each_line)

except IOError as err:
	print("file is missing! " + str(err))
finally:
	if 'data' in locals():
		data.close()
"""

try:
	with open("data.txt") as data:
		for each_line in data:
			if ( each_line != "" ):
				copy.append(each_line)
except IOError as err:
	print(str(err))

### print(copy) ###

try:
	with open("my_file.txt", "w") as my_file:
		print(copy, file=my_file)
except IOError:
	print("IO Error")


